#include "VectorSala.h"
#include "Lock.h"
#include <sstream>


void VectorSala::pushBack(Sala* sala)
{
	Lock lock(mutex);
	vec.push_back(sala);
}

Sala* VectorSala::operator [](const unsigned& pos)
{
	Lock lock(mutex);
	return vec[pos];
}

unsigned VectorSala::size()
{
	Lock lock(mutex);
	return vec.size();
}

void VectorSala::borrar(const unsigned& pos)
{
	Lock lock(mutex);
	vec.erase(vec.begin()+pos);
}

Json::Value VectorSala::getJson()
{
	Lock lock(mutex);
	Json::Value root;
	unsigned tam  = vec.size();
	root["cantDeSalas"] = tam;
	for(unsigned i = 0; i < vec.size(); i++){
		std::stringstream s;
		s << "Sala " << i+1;
		root[s.str()] = vec[i]->getJson();
	}
	return root;
}
